package com.egg.action;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import com.egg.action.common.BaseAction;
import com.egg.service.RoleService;
/**
 * @项目名称：egg   
 * @类名称：RoleAction   
 * @类描述：角色action   
 * @创建人：wangchenyang
 * @创建时间：2012-9-4 下午4:02:48   
 * @修改人：
 * @修改时间：   
 * @修改备注：   
 * @version
 */
@Namespace("/role")
@ParentPackage("default")
public class RoleAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private String roleId;
	private String userId;
	private String roleName;
	private String roleDescription;
	private List<Map<String,Object>> roleList;
	@Autowired
	RoleService roleService;
	
	@Action(value="getAllRole",results={@Result(name="success",location="/system/role/listRole.jsp")})
	public String getAllRole(){
		String deptId=String.valueOf(getSession().getAttribute("deptId"));
		roleList=roleService.getAllRole(deptId);
		return "success";
	}
	@Action(value="addOrUpdateRole",results={@Result(name="redirect",type="redirect",location="getAllRole.action")})
	public String addOrUpdateRole(){
		String deptId=String.valueOf(getSession().getAttribute("deptId"));
		if(roleId!=null&&!"".equals(roleId)){
			roleService.updateRole(roleName,roleDescription,roleId);
		}else{
			roleService.addRole(roleName,roleDescription,deptId,new Date());
		}
		return "redirect";
	}
	
	@Action(value="preUpdateRole",results={@Result(name="success",location="/system/role/addOrUpdateRole.jsp")})
	public String preUpdateRole(){
		roleList=roleService.getOneRole(roleId);
		return "success";
	}
	
	@Action(value="deleteRole",results={@Result(name="redirect",type="redirect",location="getAllRole.action")})
	public String deleteRole(){
		roleService.deleteRole(roleId);
		return "redirect";
	}
	@Action(value="getRoleData",results={@Result(name="success",location="/system/role/assignRole.jsp")})
	public String getRoleData(){
		String deptId=String.valueOf(getSession().getAttribute("deptId"));
		roleList=roleService.getRoleData(userId,deptId);
		getRequest().setAttribute("userId", userId);
		return "success";
	}
	@Action(value="assignRole",results={@Result(name="redirect",type="redirect",location="/user/getAllUser.action")})
	public String assignRole(){
		roleService.assignRole(userId,roleId);
		return "redirect";
	}
	public String getRoleId() {
		return roleId;
	}
	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	public String getRoleDescription() {
		return roleDescription;
	}
	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}
	public RoleService getRoleService() {
		return roleService;
	}
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public List<Map<String, Object>> getRoleList() {
		return roleList;
	}
	public void setRoleList(List<Map<String, Object>> roleList) {
		this.roleList = roleList;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	
}
